package com.zmn.oms.services.impl.ins;

import com.zmn.oms.model.entity.ins.InsOrderMasterCpic;
import com.zmn.oms.persistence.interfaces.ins.InsOrderMasterCpicDao;
import com.zmn.oms.services.interfaces.ins.InsOrderMasterCpicService;
import com.zmn.oms.services.interfaces.orderencrypt.InsOrderEncryptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类描述：
 *
 * @author lhl
 * @date 2021/03/25 20:26
 */
@Service("insOrderMasterCpicService")
public class InsOrderMasterCpicServiceImpl implements InsOrderMasterCpicService {

    @Resource
    private InsOrderMasterCpicDao insOrderMasterCpicDao;
    @Autowired
    private InsOrderEncryptService insOrderEncryptService;

    @Override
    public List<InsOrderMasterCpic> listByKeys(List<Long> insMasterIds) {
        List<InsOrderMasterCpic> insOrderMasterCpicsCopy = insOrderMasterCpicDao.listByKeys(insMasterIds);
        return insOrderEncryptService.batchDecryptInsOrderMasterCpic(insOrderMasterCpicsCopy);
    }

    @Override
    public List<InsOrderMasterCpic> listByOrderIds(List<Long> orderIds) {
        List<InsOrderMasterCpic> insOrderMasterCpicsCopy = insOrderMasterCpicDao.listByOrderIds(orderIds);
        return insOrderEncryptService.batchDecryptInsOrderMasterCpic(insOrderMasterCpicsCopy);
    }

    @Override
    public List<InsOrderMasterCpic> listNoSynced(Integer rows) {
        List<InsOrderMasterCpic> insOrderMasterCpicsCopy = insOrderMasterCpicDao.listNoSynced(rows);
        return insOrderEncryptService.batchDecryptInsOrderMasterCpic(insOrderMasterCpicsCopy);
    }

    @Override
    public List<InsOrderMasterCpic> listErpNoSynced(Integer rows) {
        List<InsOrderMasterCpic> insOrderMasterCpicsCopy = insOrderMasterCpicDao.listErpNoSynced(rows);
        return insOrderEncryptService.batchDecryptInsOrderMasterCpic(insOrderMasterCpicsCopy);
    }

    @Override
    public List<InsOrderMasterCpic> listFormStatusPending(Integer rows) {
        List<InsOrderMasterCpic> insOrderMasterCpicsCopy = insOrderMasterCpicDao.listFormStatusPending(rows);
        return insOrderEncryptService.batchDecryptInsOrderMasterCpic(insOrderMasterCpicsCopy);
    }

    @Override
    public List<InsOrderMasterCpic> listFormStatusFail(Integer rows) {
        List<InsOrderMasterCpic> insOrderMasterCpicsCopy = insOrderMasterCpicDao.listFormStatusFail(rows);
        return insOrderEncryptService.batchDecryptInsOrderMasterCpic(insOrderMasterCpicsCopy);
    }

    @Override
    @Transactional
    public void updateByKey(InsOrderMasterCpic model) {
        insOrderMasterCpicDao.updateByKey(model);
    }

    @Override
    @Transactional
    public void updateFormStatus2UnknowByKeys(List<Long> insMasterIds) {
        insOrderMasterCpicDao.updateFormStatus2UnknowByKeys(insMasterIds);
    }

    @Override
    @Transactional
    public void updateErpSyncSuccessByKeys(List<Long> insMasterIds) {
        insOrderMasterCpicDao.updateErpSyncSuccessByKeys(insMasterIds);
    }

    @Override
    @Transactional
    public void updateErpSyncFailByKeys(List<Long> insMasterIds) {
        insOrderMasterCpicDao.updateErpSyncFailByKeys(insMasterIds);
    }

    /**
     * 修改同步状态
     * @param list
     */
    @Override
    @Transactional
    public void updateRequestIdByKeys(List<InsOrderMasterCpic> list, String requestId, String insStartDate, String insEndDate) {
        insOrderMasterCpicDao.updateRequestIdByKeys(list, requestId, insStartDate, insEndDate);
    }

    @Override
    public int insert(InsOrderMasterCpic model) {
        InsOrderMasterCpic modelCopy = insOrderEncryptService.encryptInsOrderMasterCpic(model);
        int count = insOrderMasterCpicDao.insert(modelCopy);
        model.setInsMasterId(modelCopy.getInsMasterId());

        return count;
    }
}
